/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package POJOS;

import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author John
 */
class IncidenciaDAO {
    
    @SessionTarget
    Session session;
    
    @TransactionTarget
    Transaction transaction;

    /**
     * Used to save or update a user.
     */
    public void guardarOActualizarIncidencia(Incidencia incidencia) {
        try {
            session.saveOrUpdate(incidencia);
        } catch (Exception e) {
            transaction.rollback();
            e.printStackTrace();
        }
    }

    /**
     * Used to delete a user.
     */
    public void eliminarIncidencia(Long id) {
        try {
            Incidencia incidencia = (Incidencia) session.get(Incidencia.class, id);
            session.delete(incidencia);
        } catch (Exception e) {
            transaction.rollback();
            e.printStackTrace();
        } 
    }

    /**
     * Used to list all the users.
     */
    @SuppressWarnings("unchecked")
    public List<Incidencia> listarIncidencias(){
        List<Incidencia> incidenciaes = null;
        try {
            incidenciaes = session.createQuery("from Incidencia").list();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return incidenciaes;
    }

    /**
     * Used to list a single user by Id.
     */
    public Incidencia listarIncidenciaPorId(Long id) {
        Incidencia incidencia = null;
        try {
            incidencia = (Incidencia) session.get(Incidencia.class, id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return incidencia;
    }
    
}